package net.pulseproject.router.config.instantiator.builder;

import java.util.Collection;

import net.pulseproject.commons.midi.Receivable;
import net.pulseproject.router.config.instantiator.builder.validator.FieldValidator;
import net.pulseproject.router.config.instantiator.builder.validator.SkeletonFieldValidator;
import net.pulseproject.router.modules.logic.beatstabilizer.BeatStabilizerConfig;
import net.pulseproject.router.modules.useable.BeatStabilizerModule;


public class BeatStabilizerModuleBuilder extends BiDirectionalModuleBuilder<BeatStabilizerModule> {
	
	// TODO does it solve findbugs error UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR?
	private Integer lagTimeoutInMs = null;
	
	private Integer sustainedFireWindowInMs = null;

	private final FieldValidator validator = new SkeletonFieldValidator() {
		@SuppressWarnings("synthetic-access")
		@Override
		protected void validateFields() {
			if(BeatStabilizerModuleBuilder.this.lagTimeoutInMs == null) {
				throw new RuntimeException("lagTimeoutInMs not yet set");
			}
			if(BeatStabilizerModuleBuilder.this.sustainedFireWindowInMs == null) {
				throw new RuntimeException("sustainedFireWindowInMs not yet set");
			}
		}
	};
	
	public BeatStabilizerModuleBuilder() {
		this.addValidator(this.validator);
	}

	public final void setLagTimeoutInMs(final Integer lagTimeoutInMs) {
		this.lagTimeoutInMs = lagTimeoutInMs;
	}

	public final void setSustainedFireWindowInMs(final Integer sustainedFireWindowInMs) {
		this.sustainedFireWindowInMs = sustainedFireWindowInMs;
	}
	
	@Override
	protected final BeatStabilizerModule buildModule() {
		// FIXME implement me
		System.err.println("AAAAAAAH! implement BeatStabilizerModuleBuilder!!!!!!");
		long globalMinMs = 100;
		int globalMaxMs = 2000;
		double frameDeviationPercent = 5.0D;
		
		return new BeatStabilizerModule(this.getId(), this.getOutgoingModules(), new BeatStabilizerConfig(globalMinMs, globalMaxMs, frameDeviationPercent));
	}
	
}
